/**
 * 电商系统商品管理应用程序入口
 * 整合了系统初始化和启动功能
 */
public class AppMain {
    
    /**
     * 主方法，程序入口
     * @param args 命令行参数
     */
    public static void main(String[] args) {
        System.out.println("========== 电商系统商品管理 ==========");
        System.out.println("正在初始化系统...");
        
        // 验证商品数据文件
        initializeProductData();
        
        System.out.println("系统初始化完成，正在启动图形界面...");
        
        // 启动商品管理系统GUI
        ProductGUI.main(args);
    }
    
    /**
     * 初始化商品数据
     * 确保系统有基本的商品数据，并添加更多样化的商品
     */
    private static void initializeProductData() {
        try {
            // 检查是否有商品数据
            java.util.List<Product> existingProducts = ProductStorage.loadProducts(null);
            if (existingProducts == null || existingProducts.isEmpty()) {
                System.out.println("未发现商品数据，将创建初始商品...");
                
                // 创建初始商品数据的逻辑已在GUI中实现
                System.out.println("初始商品创建将在GUI启动时自动完成");
            } else {
                System.out.println("发现现有商品数据: " + existingProducts.size() + " 个商品");
                System.out.println("正在添加更多商品到系统中...");
                
                // 添加更多电子产品
                ElectronicProduct smartphone = new ElectronicProduct("E005", "智能手机Pro", 3999.0, "高性能智能手机，配备最新处理器", 50, "品牌A", "Pro Max", 24, "8核处理器，12GB内存");
                ElectronicProduct tablet = new ElectronicProduct("E006", "平板电脑", 2599.0, "轻薄便携平板电脑，适合办公和娱乐", 30, "品牌B", "Air", 18, "10.9英寸显示屏，64GB存储");
                ElectronicProduct wirelessHeadphones = new ElectronicProduct("E007", "无线蓝牙耳机", 899.0, "主动降噪，长续航", 100, "品牌C", "Studio", 12, "主动降噪，30小时续航");
                
                // 添加更多服装
                ClothingProduct tshirt = new ClothingProduct("C005", "纯棉T恤", 99.0, "舒适透气的纯棉短袖", 200, "M", "蓝色", "棉100%", "男女通用");
                ClothingProduct jeans = new ClothingProduct("C006", "修身牛仔裤", 299.0, "经典款式修身牛仔裤", 150, "L", "深蓝色", "棉95%, 弹性纤维5%", "男");
                ClothingProduct jacket = new ClothingProduct("C007", "轻薄夹克", 499.0, "防风防水轻薄外套", 80, "XL", "黑色", "聚酯纤维80%, 尼龙20%", "男女通用");
                
                // 添加更多食品
                FoodProduct chocolate = new FoodProduct("F005", "黑巧克力", 59.0, "高纯度黑巧克力，口感醇厚", 120, "2024-12-31", "可可豆, 糖", "热量: 539千卡/100g", false);
                FoodProduct yogurt = new FoodProduct("F006", "希腊酸奶", 35.0, "高蛋白希腊式酸奶", 150, "2024-06-15", "牛奶, 益生菌", "蛋白质: 10g/100g", true);
                FoodProduct chips = new FoodProduct("F007", "薯片", 12.0, "经典口味薯片", 300, "2024-08-31", "土豆, 植物油, 盐", "热量: 536千卡/100g", false);
                
                // 添加更多书籍
                BookProduct novel = new BookProduct("B005", "科幻小说集", 58.0, "精选科幻短篇小说合集", 50, "作者A", "出版社X", 2023, "978-7-123-45678-9", "科幻");
                BookProduct textbook = new BookProduct("B006", "Java编程基础", 89.0, "面向初学者的Java编程教材", 80, "作者B", "出版社Y", 2022, "978-7-987-65432-1", "编程");
                BookProduct biography = new BookProduct("B007", "名人自传", 45.0, "一位成功企业家的自传", 60, "作者C", "出版社Z", 2021, "978-7-567-89012-3", "传记");
                
                // 保存所有新商品
                ProductStorage.saveSingleProduct(smartphone, null);
                ProductStorage.saveSingleProduct(tablet, null);
                ProductStorage.saveSingleProduct(wirelessHeadphones, null);
                ProductStorage.saveSingleProduct(tshirt, null);
                ProductStorage.saveSingleProduct(jeans, null);
                ProductStorage.saveSingleProduct(jacket, null);
                ProductStorage.saveSingleProduct(chocolate, null);
                ProductStorage.saveSingleProduct(yogurt, null);
                ProductStorage.saveSingleProduct(chips, null);
                ProductStorage.saveSingleProduct(novel, null);
                ProductStorage.saveSingleProduct(textbook, null);
                ProductStorage.saveSingleProduct(biography, null);
                
                System.out.println("已成功添加12个新商品到系统中");
            }
        } catch (Exception e) {
            System.out.println("初始化商品数据时出错: " + e.getMessage());
            e.printStackTrace();
        }
    }
}